function probationDaysFormatter(value) {
  return `${value}天`;
}
export function basicsPages(data) {
  const fields = {};
  data.forEach(element => {
    if (element.isOpen) {
      // console.log("data", element);
      fields[element.fieldCode] = {
        model: element.fieldCode,
        type: "",
        wrapper: {
          label: element.fieldName
        },
        customize: {
          formatter:probationDaysFormatter,
          placeholder:
            element.fieldType === 2 ||
            element.fieldType === 4 ||
            element.fieldType === "2" ||
            element.fieldType === "4"
              ? `请输入${element.fieldName}`
              : `请选择${element.fieldName}`,
          format: element.fieldType === "3" ? "YYYY-MM-DD" : ""
        },
        decorator: {
          initialValue: undefined,
          formatter:'',
          rules: [
            {
              required: element.isNecessary,
              message:
                element.fieldType === 2 ||
                element.fieldType === 4 ||element.fieldType === 5 ||
                element.fieldType === "2" || element.fieldType === "5"||
                element.fieldType === "4"
                  ? `请输入${element.fieldName}`
                  : `请选择${element.fieldName}`
            }
          ]
        }
      };

      if (element.fieldType === 1 || element.fieldType === "1") {
        let options = [];
        if (element.dropDownEnumList) {
          element.dropDownEnumList.forEach((item, index) => {
            for (const key in item) {
              if (item[key] === "true") {
                item[key] = true;
              }
              if (item[key] === "false") {
                item[key] = false;
              }
            }
          });
          options = element.dropDownEnumList;
        }
        if (element.dropDownArray) {
          element.dropDownArray.forEach(element => {
            options.push({
              value: element,
              label: element
            });
          });
        }
        fields[element.fieldCode].customize.options = options;
        fields[element.fieldCode].type = "select";
      }

      if (element.fieldType === 2 || element.fieldType === "2") {
        fields[element.fieldCode].type = "input";
      }

      if (element.fieldType === 3 || element.fieldType === "3") {
        fields[element.fieldCode].type = "date";
      }

      if (element.fieldType === 4 || element.fieldType === "4") {
        fields[element.fieldCode].type = "textarea";
      }

      if (element.fieldType === 5 || element.fieldType === "5") {
        fields[element.fieldCode].type = "number";
        fields[element.fieldCode].decorator.rules.push({
          pattern: "^\\d+$",
          message: `${element.fieldName}必须为数字`
        });
      }

      if (element.fieldType === 6 || element.fieldType === "6") {
        fields[element.fieldCode].type = "area";
      }

      if (element.fieldType === 7 || element.fieldType === "7") {
        fields[element.fieldCode].type = "upload";
        fields[element.fieldCode].customize = {
          accept: ".jpg, .jpeg, .png",
          listType: "picture-card",
          maxCount: 8
        };
      }

      if (element.fieldCode === "phone" || element.fieldCode === "witPhone") {
        fields[element.fieldCode].decorator.rules.push({
          pattern: "^1[3456789]\\d{9}$",
          message: `${element.fieldName}格式错误`
        });
      }
      if (element.fieldCode === "idcard" || element.fieldCode === "idCard") {
        // fields[element.fieldCode].decorator.rules.push({
        //   pattern:
        //     "^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$",
        //   message: `${element.fieldName}格式错误`
        // });
        fields[element.fieldCode].decorator.rules.push({
          pattern:
          "^((^[HMhm](\\d{8}|\\d{10})$)|(^(\\d{8}|^[a-zA-Z]{1}(\\d{7}))$)|(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx]$)))$",
          message: `${element.fieldName}格式错误`
        });
      }
      if (element.fieldCode === "email") {
        fields[element.fieldCode].decorator.rules.push({
          pattern:
            "^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$",
          message: `${element.fieldName}格式错误`
        });
      }
    }
  });
  return fields;
}
